From d7c5c4fb420fe67016f47ec04648082cca36e1e2 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 14 Apr 2010 01:10:44 +0000 Subject: [PATCH] Add core support for track segement. Read and write in GPX. --- defs.h | 1 + gpx.c | 25 +++++++++++++++++++++++-- route.c | 14 +++++++++++++- tpo.c | 2 +- xmldoc/chapters/build.xml | 2 +- xmldoc/chapters/preface.xml | 2 +- xmldoc/chapters/styles.xml | 2 +- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/defs.h b/defs.h index 24d39ce49..8f24fc142 100644 --- a/defs.h +++ b/defs.h @@ -355,6 +355,7 @@ typedef struct { ... and others */ unsigned int is_split:1; /* the waypoint represents a split */ + unsigned int new_trkseg:1; /* True if first in new trkseg. */ } wp_flags; diff --git a/gpx.c b/gpx.c index 1be06754a..2e0b675b9 100644 --- a/gpx.c +++ b/gpx.c @@ -64,8 +64,10 @@ static char *suppresswhite = NULL; static char *urlbase = NULL; static route_head *trk_head; static route_head *rte_head; +static const route_head *current_trk_head; // Output. /* used for bounds calculation on output */ static bounds all_bounds; +static int next_trkpt_is_new_seg; static format_specific_data **fs_ptr; @@ -692,6 +694,10 @@ gpx_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr) break; case tt_trk_trkseg_trkpt: tag_wpt(attr); + if (next_trkpt_is_new_seg) { + wpt_tmp->wpt_flags.new_trkseg = 1; + next_trkpt_is_new_seg = 0; + } break; case tt_unknown: start_something_else(el, attr); @@ -1050,6 +1056,9 @@ gpx_end(void *data, const XML_Char *xml_el) break; case tt_trk: break; + case tt_trk_trkseg: + next_trkpt_is_new_seg = 1; + break; case tt_trk_trkseg_trkpt: track_add_wpt(trk_head, wpt_tmp); wpt_tmp = NULL; @@ -1705,6 +1714,7 @@ static void gpx_track_hdr(const route_head *rte) { fs_xml *fs_gpx; + current_trk_head = rte; gbfprintf(ofd, "\n"); write_optional_xml_entity(ofd, " ", "name", rte->rte_name); @@ -1720,13 +1730,21 @@ gpx_track_hdr(const route_head *rte) } } - gbfprintf(ofd, "\n"); } static void gpx_track_disp(const waypoint *waypointp) { fs_xml *fs_gpx; + int first_in_trk; + first_in_trk = waypointp->Q.prev == ¤t_trk_head->waypoint_list; + + if (waypointp->wpt_flags.new_trkseg) { + if (!first_in_trk) { + gbfprintf(ofd, "\n"); + } + gbfprintf(ofd, "\n"); + } gbfprintf(ofd, "\n", waypointp->latitude, @@ -1766,8 +1784,11 @@ gpx_track_disp(const waypoint *waypointp) static void gpx_track_tlr(const route_head *rte) { - gbfprintf(ofd, "\n"); + if (!QUEUE_EMPTY(¤t_trk_head->waypoint_list)) { + gbfprintf(ofd, "\n"); + } gbfprintf(ofd, "\n"); + current_trk_head = NULL; } static diff --git a/route.c b/route.c index e6f8b1ff6..bfd378d3e 100644 --- a/route.c +++ b/route.c @@ -189,6 +189,13 @@ route_add_wpt( route_head *rte, waypoint *wpt ) void track_add_wpt( route_head *rte, waypoint *wpt ) { + // First point in a track is always a new segment. + // This improves compatibility when reading from + // segment-unaware formats. + if (QUEUE_EMPTY(&rte->waypoint_list)) { + wpt->wpt_flags.new_trkseg = 1; + } + any_route_add_wpt( rte, wpt, &trk_waypts, 0 ); } @@ -209,6 +216,11 @@ route_find_waypt_by_name( route_head *rh, const char *name ) static void any_route_del_wpt( route_head *rte, waypoint *wpt, int *ct) { + if (wpt->wpt_flags.new_trkseg && wpt != (waypoint*)QUEUE_LAST(&rte->waypoint_list)) { + waypoint* wpt_next = (waypoint*)QUEUE_NEXT(&wpt->Q); + wpt_next->wpt_flags.new_trkseg = 1; + } + wpt->wpt_flags.new_trkseg = 0; dequeue( &wpt->Q ); rte->rte_waypt_ct--; if ( ct ) (*ct)--; @@ -236,7 +248,7 @@ route_disp (const route_head *rh, waypt_cb cb ) QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) { waypoint *waypointp; waypointp = (waypoint *) elem; - (*cb)(waypointp); + (*cb)(waypointp); } } diff --git a/tpo.c b/tpo.c index 45a6491b2..253e681ec 100644 --- a/tpo.c +++ b/tpo.c @@ -670,7 +670,7 @@ void tpo_process_tracks(void) llvalid = 1; waypoint_temp = tpo_convert_ll(lat, lon); - route_add_wpt(track_temp, waypoint_temp); + track_add_wpt(track_temp, waypoint_temp); waypoint_count++; } diff --git a/xmldoc/chapters/build.xml b/xmldoc/chapters/build.xml index 66ec48090..9bcb3584d 100644 --- a/xmldoc/chapters/build.xml +++ b/xmldoc/chapters/build.xml @@ -1,5 +1,5 @@ - Getting it or Building it + Getting or Building GPSBabel Downloading - the easy way. diff --git a/xmldoc/chapters/preface.xml b/xmldoc/chapters/preface.xml index e83e1560d..469cfbe8f 100644 --- a/xmldoc/chapters/preface.xml +++ b/xmldoc/chapters/preface.xml @@ -1,5 +1,5 @@ - Introduction + Introduction to GPSBabel
The Problem: Too many incompatible GPS file formats There are simply too many gratuitously different file formats diff --git a/xmldoc/chapters/styles.xml b/xmldoc/chapters/styles.xml index 26f9c4937..49a0188ef 100644 --- a/xmldoc/chapters/styles.xml +++ b/xmldoc/chapters/styles.xml @@ -2,7 +2,7 @@ GPSBabel XCSV Style Files
-Introduction +Introduction to GPSBabel Styles Often it is desirable to add a new file format for "one-off" work (perhaps you want to export something to a spreadsheet or graphing program) or to read -- 2.30.2